package com.kg.fiber;

import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

import com.kg.fiber.view.MainFrame;

import lombok.Getter;
import lombok.extern.log4j.Log4j;

@SpringBootApplication
@Log4j
public class FiberviewApplication {
	
	@Getter
	private static ConfigurableApplicationContext spring;

	public static void main(String[] args) {
		
        try {
        	
        	UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        	
        	Font font = new Font("微软雅黑", Font.PLAIN, 12);
        	java.util.Enumeration<?> keys = UIManager.getDefaults().keys();
        	while (keys.hasMoreElements())
        	{
        		Object key = keys.nextElement();
        		Object value = UIManager.get(key);
        		if (value instanceof javax.swing.plaf.FontUIResource)
        		{
        			UIManager.put(key, font);
        		}
        	}
			
        } catch ( Exception e ) {
        	
            JOptionPane.showMessageDialog(
            		null, 
            		"设置界面风格失败", 
            		"错误", 
            		JOptionPane.INFORMATION_MESSAGE);
        }
        
		SpringApplicationBuilder builder = new SpringApplicationBuilder(FiberviewApplication.class);
		
		spring = builder.headless(false).run(args);
		
		//ConfigurableApplicationContext cac = builder.headless(false).run(args);
		
		
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				
				try {
					MainFrame mf = new MainFrame();
					mf.setVisible(true);
				} catch(Exception e) {
					log.error("Show main frame failed.", e);
				}				
				
			}
			
			
		});
		

        
	}
}
